﻿#region

using ThuySan.Bussiness;
using ThuySan.IRepository;
using ThuySan.Repository;

#endregion

namespace ThuySan.Models
{
    public class UnitOfWork
    {
        private ICategoryPropertyRepository _categoryPropertyRepository;

        private ICategoryRepository _categoryRepository;

        private ICategoryTagRepository _categoryTagRepository;

        private IImageRepository _imageRepository;

        private IProductPropertyRepository _productPropertyRepository;

        private IProductRepository _productRepository;

        private IProductTagRepository _productTagRepository;

        private IPropertyRepository _propertyRepository;

        private ITagRepository _tagRepository;

        private ISettingRepository _settingRepository;

        private IWebUserRepository _userRepository;

        private IEmailTemplateRepository _emailTemplateRepository;

        public UnitOfWork()
        {
            Context = new FishesStoreContext(); // Name of ConnectionString in Web.config
        }

        public FishesStoreContext Context { get; set; }

        public ICategoryRepository CategoryRepository
        {
            get { return _categoryRepository ?? (_categoryRepository = new CategoryRepository(Context)); }
            set { _categoryRepository = value; }
        }

        public IProductRepository ProductRepository
        {
            get { return _productRepository ?? (_productRepository = new ProductRepository(Context)); }
            set { _productRepository = value; }
        }

        public ITagRepository TagRepository
        {
            get { return _tagRepository ?? (_tagRepository = new TagRepository(Context)); }
            set { _tagRepository = value; }
        }

        public IProductTagRepository ProductTagRepository
        {
            get { return _productTagRepository ?? (_productTagRepository = new ProductTagRepository(Context)); }
            set { _productTagRepository = value; }
        }

        public IPropertyRepository PropertyRepository
        {
            get { return _propertyRepository ?? (_propertyRepository = new PropertyRepository(Context)); }
            set { _propertyRepository = value; }
        }

        public ICategoryPropertyRepository CategoryPropertyRepository
        {
            get { return _categoryPropertyRepository ?? (_categoryPropertyRepository = new CategoryPropertyRepository(Context)); }
            set { _categoryPropertyRepository = value; }
        }

        public IProductPropertyRepository ProductPropertyRepository
        {
            get { return _productPropertyRepository ?? (_productPropertyRepository = new ProductPropertyRepository(Context)); }
            set { _productPropertyRepository = value; }
        }

        public ICategoryTagRepository CategoryTagRepository
        {
            get { return _categoryTagRepository ?? (_categoryTagRepository = new CategoryTagRepository(Context)); }
            set { _categoryTagRepository = value; }
        }

        public IImageRepository ImageRepository
        {
            get { return _imageRepository ?? (_imageRepository = new ImageRepository(Context)); }
            set { _imageRepository = value; }
        }

        public ISettingRepository SettingRepository
        {
            get { return _settingRepository ?? (_settingRepository=new SettingRepository(Context)); }
            set { _settingRepository = value; }
        }

        public IWebUserRepository UserRepository
        {
            get { return _userRepository ?? (_userRepository=new WebUserRepository(Context)); }
            set { _userRepository = value; }
        }

        public IEmailTemplateRepository EmailTemplateRepository
        {
            get { return _emailTemplateRepository ?? (_emailTemplateRepository=new EmailTemplateRepository(Context)); }
            set { _emailTemplateRepository = value; }
        }

        public void AcceptChanges()
        {
            Context.SaveChanges();
        }
    }
}
